/*
 * Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
 */
package com.pitop.sync.ctrl;


import com.pitop.core.entity.BeanRet;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.sync.service.SyncNewDataSVImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 需要同步的数据 控制器
 *
 * @author pi-top
 */
@RestController
@RequestMapping("/syncNewData")
@Slf4j
@Api(value = "需要同步的数据控制器", description = "需要同步的数据控制器")
public class SyncNewDataCtrl {

    @Autowired
    private SyncNewDataSVImpl syncNewDataSVImpl;


    /**
     * 从云端往工厂端同步数据调度接口
     */
    @ApiOperation(value = "从云端往工厂端同步数据调度接口", notes = "从云端往工厂端同步数据调度接口")
    @ApiImplicitParam(name = "factoryCode", value = "factoryCode", dataType = "String", required = true, paramType = "query")
    @RequestMapping(value = "/syncDataToDown", method = RequestMethod.POST)
    @ResponseBody
    public BeanRet syncDataToDown(@RequestBody String param) throws Exception {
        if (StringUtils.isBlank(param)) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        return syncNewDataSVImpl.syncDataToDown(param);
    }

    /**
     * 获取工厂端数据同步结果
     */
    @ApiOperation(value = "获取工厂端数据同步结果", notes = "获取工厂端数据同步结果")
    @ApiImplicitParam(name = "syncResult", value = "syncResult", dataType = "String", required = true, paramType = "query")
    @RequestMapping(value = "/updateStateBySyncResult", method = RequestMethod.POST)
    @ResponseBody
    public BeanRet updateStateBySyncResult(@RequestBody String syncResult) {
        //TODO 如果测试不需要了就删除即可
        log.debug(syncResult + "\n");
        if (StringUtils.isBlank(syncResult)) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        return syncNewDataSVImpl.updateStateBySyncResult(syncResult);
    }
}
